# Maintainer: David Macek <david.macek.0@gmail.com>

# todo fix or explain: -DDEBUG -DWIN32S_COMPAT -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP -DNO_SECUREZEROMEMORY
# todo check if unix directory is interesting
# todo install docs

_realname=putty
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=0.67.r4371.5c5879b
pkgrel=1
pkgdesc="A free telnet/SSH client (mingw-w64)"
arch=('any')
url="http://www.chiark.greenend.org.uk/~sgtatham/putty/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=("${MINGW_PACKAGE_PREFIX}-putty-ssh: ssh wrapper for plink")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
source=("${_realname}"::"git://git.tartarus.org/simon/putty.git"
        '0001-fixes.patch'
        '0003-linedraw.patch')
sha256sums=('SKIP'
            '07f354b2fc3517f4051214bd67ca07af73251c6f17cc77570a6b53434c7109a5'
            '344e01c8032b258532c2edd2eb468adceab7c90f73ca38171487d9fa696a112e')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "%s.r%s.%s" "$(cat LATEST.VER)" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
  # git describe --tags --abbrev=0 gives wrong results
}

prepare() {
  cd "${srcdir}"/${_realname}
  patch -p1 -i "${srcdir}"/0001-fixes.patch
  patch -p1 -i "${srcdir}"/0003-linedraw.patch
  mkdir -p "${srcdir}"/${_realname}-build-${CARCH}
  cp -r "${srcdir}"/${_realname}/* "${srcdir}"/${_realname}-build-${CARCH}
}

build() {
  cd "${srcdir}"/${_realname}-build-${CARCH}

  ./mkfiles.pl
  cd windows
  if [ "${CARCH}" = "x86_64" ]; then
    sed -i 's/x86/amd64/' *.mft
  fi
  make -f Makefile.cyg
}

package() {
  cd "${srcdir}"/${_realname}-build-${CARCH}/windows
  install -D -m644 ../LICENCE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
  for f in putty puttygen pageant plink pscp psftp puttytel
  do
    install -D -m755 ${f}.exe "${pkgdir}"/${MINGW_PREFIX}/bin/${f}.exe
  done
}
